﻿//using MusicExplorer.Model;
//using System;
//using System.Collections.Generic;
//using System.ComponentModel;
//using System.Linq;
//using System.Runtime.CompilerServices;
//using System.Text;
//using System.Threading.Tasks;
//using Windows.UI.Core;

//namespace MusicExplorer.Common
//{
//    public abstract class ViewModelBase : INotifyPropertyChanged
//    {
//        public event PropertyChangedEventHandler PropertyChanged = delegate { };

//        public virtual ViewModelBase GetParent() { return null; }

//        public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
//        {
//            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
//        }
//    }

//    public abstract class ViewModelBase<TParent> : ViewModelBase where TParent : ViewModelBase
//    {
//        private readonly TParent m_parent;

//        public ViewModelBase(TParent parent)
//        {
//            m_parent = parent;
//        }

//        public TParent Parent { get { return m_parent; } }

//        public override ViewModelBase GetParent() { return m_parent; }
//    }

//    public abstract class AsyncViewModelBase : ViewModelBase<ViewModelBase>
//    {
//        protected AsyncViewModelBase(ViewModelBase parent) : base(parent) { }

//        protected abstract Task InitializeAsync(NavigationObject obj);

//        public static async Task<T> CreateAsync<T>(NavigationObject obj) where T : AsyncViewModelBase
//        {
//            T ret;
//            if(obj != null)
//                ret = (T)Activator.CreateInstance(typeof(T), obj.Parent);
//            else
//                ret = (T)Activator.CreateInstance(typeof(T));
//            await ret.InitializeAsync(obj);
//            return ret;
//        }
//    }

//    public abstract class PageViewModelBase : AsyncViewModelBase
//    {
//        protected PageViewModelBase(ViewModelBase parent) : base(parent)
//        {
//        }

//        public abstract string Title { get; }

//        public string CompleteTitle
//        {
//            get
//            {
//                var builder = new StringBuilder();
//                builder.Append(Title);

//                var parent = GetParent() as PageViewModelBase;
//                while (parent != null)
//                {
//                    builder.Insert(0, string.Format("{0} > ", parent.Title));
//                    parent = parent.GetParent() as PageViewModelBase;
//                }

//                return builder.ToString();
//            }
//        }
//    }
//}

using Caliburn.Micro;
using System;

namespace MusicExplorer.Common
{

    /// <summary>
    /// Base view model for all our main screens, the method GoBack will be bound via convention
    /// to the back button and only display when it can go back due to the template of the back 
    /// button (Collapsed when Disabled)
    /// </summary>
    public abstract class ViewModelBase : Screen
    {
        private readonly INavigationService navigationService;

        protected ViewModelBase(INavigationService navigationService)
        {
            this.navigationService = navigationService;
        }

        public void GoBack()
        {
            navigationService.GoBack();
        }

        public bool CanGoBack
        {
            get
            {
                return navigationService.CanGoBack;
            }
        }
    }
}
